<?php
/**
 * 轮播图模型
 */

namespace app\api\model;

use PDOStatement;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\Model;

class Banner extends Model {

    /**
     * 首页banner
     * @return array|PDOStatement|string|Collection
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     */
    public function getIndexBanner() {
        $data = $this->where('status', 1)->where('seat', 1)->order('sort','asc')->select();
        for ($i = 0; $i < count($data); $i++) {
            $data[$i]['itime'] = detail_time($data[$i]['itime']);
        }
        return $data;
    }

    /**
     * 房源banner
     * @return array|PDOStatement|string|Collection
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     */
    public function getHouseBanner() {
        $data = $this->where('status', 1)->where('seat', 2)->select();
        for ($i = 0; $i < count($data); $i++) {
            $data[$i]['itime'] = detail_time($data[$i]['itime']);
        }
        return $data;
    }

    /**
     * 名师讲堂
     * @return array|PDOStatement|string|Collection
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     */
    public static function teacherForum() {
        return db('banner')
            ->field('url,link,type')
            ->where('seat', 3)
            ->where('status', 1)
            ->select();
    }

    /**
     * 系统消息banner
     * @return array|PDOStatement|string|Collection
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     */
    public static function systembanner() {
        return db('banner')
            ->field('url,link,type')
            ->where('seat', 4)
            ->where('status', 1)
            ->find();
    }

}
